package com.zyg.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zyg.pojo.House;
import com.zyg.pojo.User;
import com.zyg.service.HouseService;
import com.zyg.service.UserService;

@Controller
public class HouseController {


	@Autowired
	private HouseService houseService;
	
	@RequestMapping("/showHouse.action")
	public String showHouse(Model model){
		List<House>list = houseService.findHouse();
		model.addAttribute("listHouse", list);
		return "house/listHouse";
	}
	@RequestMapping("/updateHouseById.action")
	public String updateHouse(int id,Model model){
		House house = houseService.findHouseById(id);
		model.addAttribute("house", house);
		return "house/updateHouse";
	}
	@RequestMapping("/updateHouse.action")
	public String update(House house){
		System.out.println(house);
		houseService.updateHouse(house);
		return "redirect:/showHouse.action";
	}
	@RequestMapping("/delHouseById.action")
	public String delHouse(int id){
		houseService.delHouse(id);
		return "redirect:/showHouse.action";
	}
	@RequestMapping("/addHouse.action")
	public String showAddHouse(){
		
		return "house/addHouse";
	}
	@RequestMapping("/insertHouse.action")
	public String insertHouse(House house){
		houseService.insertHouse(house);
		return "redirect:/showHouse.action";
	}
}
